package harima.collision.bodies;

import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;

public class Body_Collision extends Rectangle2D.Float {

	protected BodiesContext context;
	protected boolean solid;
	public boolean isSolid(){return solid;}
	public void setSolid(boolean _solid){solid = _solid;}
	
	
	public BodiesContext getContext() {
		return context;
	}

	public void setContext(BodiesContext _context) {
		context = _context;
	}

	protected boolean checkLineCollision(Line2D.Float line, Rectangle2D.Float owner) {
		boolean collision = false;

		
		if(isSolid())
		{
			for (Body body : context.getBodies()) {
				
				if (owner != body && body.isSolid() && body.intersectsLine(line)) {

					collision = true;
					break;
				}
			}
			
		}
		

		return collision;
	}

	protected Body getLineCollision(Line2D.Float line, Rectangle2D.Float owner) {
		Body collisionBody = null;

		if(isSolid())
		{
			for (Body body : context.getBodies()) {
				if(body != owner && body.isSolid() && body.intersectsLine(line))
				{
						collisionBody = body;
						break;
				}
			}

		}

		return collisionBody;
	}
}
